import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }

        Solution solution = new Solution();
        System.out.println(solution.triangleNumber(array));
    }
}

class Solution {
    public int triangleNumber(int[] nums) {
        int n = nums.length;
        int res = 0;
        Arrays.sort(nums);
        for (int i = n - 1; i >=  2; i--) {
            int l = 0;
            int r = i - 1;
            while(l<r){
                if(nums[l] + nums[r] > nums[i]){
                    res += (r - l);
                    r--;
                }else{
                    l++;
                }
            }
        }
        return res;
    }
}
class Solution1 {
    public int triangleNumber(int[] nums) {
        int n = nums.length;
        int res = 0;

        Arrays.sort(nums);
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    if(nums[i] + nums[j] > nums[k]){
                        res++;
                    }else{
                        break;
                    }
                }
            }
        }
        return res;
    }
}